package com.xxl.baselib.baseui.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.FrameLayout;

import com.xxl.baselib.R;
import com.xxl.baselib.app.AppManager;
import com.xxl.baselib.baseui.widget.TitleBar;

/**
 * Created by WEIYI on 2015/10/13.
 */
public abstract class BaseWyActivity extends AppCompatActivity {

    private TitleBar titleBar;

    @Override
    final protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AppManager.getAppManager().addActivity(this);
        setContentView(R.layout.activity_base);
        titleBar = (TitleBar) findViewById(R.id.title_bar);
        FrameLayout contentView = (FrameLayout) findViewById(R.id.content_view);
        contentView.addView(getLayoutInflater().inflate(getLayoutId(), contentView, false));
        initWyView();
        setHasBack(hasBack());
    }

    protected void initWyView() {
    }

    public void setTitle(String s) {
        titleBar.setTitle(s);
    }

    public void setVisiable() {
        titleBar.setVisibility(View.VISIBLE);
    }

    public void setGone() {
        titleBar.setVisibility(View.GONE);
    }

    public TitleBar getTitleBar() {
        return titleBar;
    }

    protected abstract int getLayoutId();

    @Override
    protected void onDestroy() {
        super.onDestroy();
        AppManager.getAppManager().finishActivity(this);
    }

    public void setHasBack(boolean hasBack) {
        if (hasBack) {
            titleBar.hasBack(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    finish();
                }
            });
        }
    }

    public boolean hasBack() {
        return false;
    }

    public void setRightClick(View.OnClickListener onClickListener, String str) {
        titleBar.hasRight(onClickListener, str);
    }



}
